<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;

use Elasticsearch\ClientBuilder;

class TestController extends Controller
{
    public $client = null;

    public function __construct() {
        $this-> client = ClientBuilder::create()->build();
    }

    public function index()
    {
        $params = [
            'index' => 'my_index',
            'type' => 'my_type',
            'id' => 'my_id',
            'body' => ['testField' => 'abc']
        ];

        //$response = $this->client->index($params);
        $a = app('es')->get(['index' => 'name', 'id' => 2]);
        dd($a);
    }

    public function testdb()
    {
        $id = 1;
        $info = User::where(['id' => $id])->first()->toArray();

        $params = [
            'index' => 'name1',
            'type' => 'title',
            'id' => $id,
            'body' => ['testField' => $info]
        ];

        $response = $this->client->index($params);
        dd($response);
    }

    public function testmysql()
    {
        $client = ClientBuilder::create()->build();
        $data = [
            'type' => 'title'
        ];
        $response = $client->search($data);
        dd($response['hits']['hits']);
        return $response['hits']['hits'];
    }

}





